package com.travel.service.impl.admin;

import com.travel.mapper.log.ApiLogMapper;
import com.travel.model.entity.log.ApiLog;
import com.travel.service.Service.ApiStatisticsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
//api统计服务实现类 记录api调用 获取api统计数据
@Service
@RequiredArgsConstructor
public class ApiStatisticsServiceImpl implements ApiStatisticsService {

    private final ApiLogMapper apiLogMapper;

    @Override
    public List<Map<String, Object>> getApiStatistics() {
        return apiLogMapper.getApiStatistics();
    }

    @Override
    public void recordApiCall(String path, String method, int statusCode, long duration) {
        ApiLog log = new ApiLog();
        log.setPath(path);
        log.setMethod(method);
        log.setStatusCode(statusCode);
        log.setResponseTime(duration);
        log.setRequestTime(LocalDateTime.now());
        apiLogMapper.insert(log);
    }
} 